//
//  HNSH_BusinessCircleCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/27.
//

#import "HNSH_BusinessCircleCell.h"

@interface HNSH_BusinessCircleCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;
/* imgView */
@property (nonatomic, strong) UIImageView *imgView;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;
/* phoneImgView */
@property (nonatomic, strong) UIImageView *phoneImgView;
/* phoneLabel */
@property (nonatomic, strong) UILabel *phoneLabel;
/* addressImgView */
@property (nonatomic, strong) UIImageView *addressImgView;
/* addressLabel */
@property (nonatomic, strong) UILabel *addressLabel;
/* 距离 */
@property (nonatomic, strong) UILabel *jlLabel;

/* detailLabel */
@property (nonatomic, strong) UILabel *detailLabel;
/* detailImgV */
@property (nonatomic, strong) UIImageView *detailImgV;
@end

@implementation HNSH_BusinessCircleCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor appBGColor];
        self.backgroundColor = [UIColor appBGColor];
        [self confiUI];
    }
    return self;
}

- (void)setModel:(HNSH_BusinessCircleListModel *)model {
    _model = model;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.image_url]];
    self.nameLabel.text = model.name;
    self.desLabel.text = [NSString stringWithFormat:@"经营%@",model.category_name];
    self.phoneLabel.text = model.phone;
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@",model.region_name,model.address];
    self.jlLabel.text = [NSString stringWithFormat:@"据您:约%@",model.distance_text];
}

- (void)confiUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.imgView];
    [self.bgView addSubview:self.nameLabel];
    [self.bgView addSubview:self.desLabel];
    [self.bgView addSubview:self.phoneLabel];
    [self.bgView addSubview:self.phoneImgView];
    [self.bgView addSubview:self.addressLabel];
    [self.bgView addSubview:self.addressImgView];
    [self.bgView addSubview:self.jlLabel];
    [self.bgView addSubview:self.detailLabel];
    [self.bgView addSubview:self.detailImgV];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.width.height.mas_equalTo(108);
        make.centerY.equalTo(self.bgView.mas_centerY);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(12);
        make.height.mas_equalTo(22);
        make.top.equalTo(self.imgView.mas_top);
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(12);
        make.height.mas_equalTo(17);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(2);
    }];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(32);
        make.height.mas_equalTo(17);
        make.width.mas_equalTo(200);
        make.top.equalTo(self.desLabel.mas_bottom).offset(7);
    }];
    
    [self.phoneImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.phoneLabel.mas_left).offset(-4);
        make.width.height.mas_equalTo(16);
        make.centerY.equalTo(self.phoneLabel.mas_centerY);
    }];
    
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(32);
        make.height.mas_equalTo(17);
        make.width.mas_equalTo(200);
        make.top.equalTo(self.phoneLabel.mas_bottom).offset(5);
    }];
    
    [self.addressImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.addressLabel.mas_left).offset(-4);
        make.width.height.mas_equalTo(16);
        make.centerY.equalTo(self.addressLabel.mas_centerY);
    }];
    
    [self.jlLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(32);
        make.height.mas_equalTo(17);
        make.width.mas_equalTo(200);
        make.top.equalTo(self.addressLabel.mas_bottom).offset(4);
    }];
    
    [self.detailImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.bottom.mas_equalTo(-14);
        make.width.height.mas_equalTo(12);
    }];
    
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.detailImgV.mas_centerY);
        make.right.equalTo(self.detailImgV.mas_left).offset(0);
        make.height.mas_equalTo(22);
    }];
    
//    self.imgView.backgroundColor = [UIColor orangeColor];
//    self.nameLabel.text = @"华联超市";
//    self.desLabel.text = @"经营商超百货";
//    self.phoneLabel.text = @"13512345678";
//    self.addressLabel.text = @"浙江省杭州市西湖区中大银泰..";
//    self.jlLabel.text = @"据您:约323.53km";
}

#pragma mark lazy

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        _bgView.layer.cornerRadius = 8;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UIImageView *)imgView {
    if (!_imgView) {
        _imgView = [[UIImageView alloc]init];
        _imgView.contentMode = UIViewContentModeScaleAspectFill;
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
    }
    return _imgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"";
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _nameLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.text = @"";
        _desLabel.textColor = [UIColor appOrangeLabelColor];
        _desLabel.font = [UIFont systemFontOfSize:12];
    }
    return _desLabel;
}

- (UIImageView *)phoneImgView {
    if (!_phoneImgView) {
        _phoneImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"b_circle_cell_phone_icon"]];
    }
    return _phoneImgView;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [[UILabel alloc]init];
        _phoneLabel.text = @"";
        _phoneLabel.textColor = [UIColor appBlackLabelColor];
        _phoneLabel.font = [UIFont systemFontOfSize:12];
    }
    return _phoneLabel;
}

- (UIImageView *)addressImgView {
    if (!_addressImgView) {
        _addressImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"b_circle_cell_address_icon"]];
    }
    return _addressImgView;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc]init];
        _addressLabel.text = @"";
        _addressLabel.textColor = [UIColor appBlackLabelColor];
        _addressLabel.font = [UIFont systemFontOfSize:12];
    }
    return _addressLabel;
}

- (UILabel *)jlLabel {
    if (!_jlLabel) {
        _jlLabel = [[UILabel alloc]init];
        _jlLabel.text = @"";
        _jlLabel.textColor = [UIColor appGrayLabelColor];
        _jlLabel.font = [UIFont systemFontOfSize:12];
    }
    return _jlLabel;
}

- (UILabel *)detailLabel {
    if (!_detailLabel) {
        _detailLabel = [[UILabel alloc]init];
        _detailLabel.text = @"看详情";
        _detailLabel.textColor = [UIColor appGrayLabelColor];
        _detailLabel.font = [UIFont boldSystemFontOfSize:12];
    }
    return _detailLabel;
}

- (UIImageView *)detailImgV {
    if (!_detailImgV) {
        _detailImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"b_circle_cell_detail_icon"]];
    }
    return _detailImgV;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
